function trim(val)
{
	 return val.replace(/(^\s*)|(\s*$)/g, "");  
}
 
function isMaxLen(o)
{  
	 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";  
	 if(o.getAttribute && o.value.length>nMaxLen)
	 {      
	 	  o.value=o.value.substring(0,nMaxLen);  
	 }  
}
 
 
  
function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function judgeCheck()
{
    var pkid_string = '';
		var listsize = document.getElementById('listsize').value;
		for(var i=0;i<listsize;i++)
		{
				if(document.getElementById('checkone'+i).checked)
				{
					pkid_string += document.getElementById('checkone'+i).value+'|';
				}
		}
    return pkid_string;
}

function setGoodsType(val)
{
  if(val=='2')
  {
    document.getElementById('p_d').style.display ='inline';
  }else{
    document.getElementById('p_d').style.display ='none';
  }
}


function changeTime(val){

	var obj = document.getElementById(val+'_operating').value;
	if( obj == '' || obj.indexOf('-')>-1 || obj=='c' || obj=='d'){
		document.getElementById(val+'_g').style.display = 'none';
	}else{
		document.getElementById(val+'_g').style.display = 'inline';
	}
}

function updatestate(val){
	var oper = document.getElementById(val+'_operating').value;
	var listsize = document.getElementById('listsize').value;
	var ifcomment='';
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	document.getElementById('pkid').value = pkid_string;
	if(pkid_string == ''){
		alert('请选择要操作的信息!');
		return false;
	}
	if(oper =='')
	{
	  alert('请选择操作方式!');
	  return false;
	}
	else if(oper == '-')
	{
	   document.getElementById('pkid').value = pkid_string;
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认删除?'))
	   {
		  document.indexForm.submit();
	   }
	}
	else if(oper=='c' || oper=='d')
	{
	   
	   document.getElementById('pkid').value = pkid_string;
	   document.getElementById('state_code').value = oper;
	   document.getElementById('bpm_id').value = '6987';
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认提交吗?'))
	   {
		  document.indexForm.submit();
	   }
	}
	else
	{
	    document.getElementById('pkid').value = pkid_string;
		document.getElementById('up_operating').value = oper;
		document.getElementById('s_start_date').value = document.getElementById(val+'_start_date').value;
		document.getElementById('s_end_date').value = document.getElementById(val+'_end_date').value;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '2491';
		if(window.confirm('确认提交吗?'))
		{
			document.indexForm.submit();
		}
	
	 }
}


function deleteOneInfo(pkid,bpm_id)
{
 
	if(window.confirm('确认删除吗？'))
	{
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}


function subForm(){
	
  if(trim(document.getElementById('goods_name').value)=="")
  {
      alert('请输入商品名称！');
      return; 
  }
  if(trim(document.getElementById('keywords').value)=='')
  {
      alert('请输入商品关键字！');
      return; 
  }
  if(trim(document.getElementById('goods_no').value)=='')
  {
      alert('请输入商品编号！');
      return; 
  }
  if(trim(document.getElementById('market_price').value)=='')
  {
      alert('请输入市场价！');
      return; 
  } 
  if(trim(document.getElementById('sale_price').value)=='')
  {
      alert('请输入销售价！');
      return; 
  }
  if(trim(document.getElementById('org_price').value)=='')
  {
      alert('请输入进价！');
      return; 
  }
  if(trim(document.getElementById('send_inter').value)=='')
  {
      alert('请输入赠送积分数！');
      return; 
  }
  if(trim(document.getElementById('buy_inter').value)=='')
  {
      alert('请输入积分购买数！');
      return; 
  }
  if(trim(document.getElementById('weight').value)=='')
  {
      alert('请输入商品重量！');
      return; 
  }
  if(document.getElementById('price_unit').value=='')
  {
      alert('请选择计价单位！');
      return; 
  }
  if(trim(document.getElementById('stock_in').value)=='')
  {
      alert('请输入库存初始量！');
      return; 
  }
  if(trim(document.getElementById('stock_down').value)=='')
  {
      alert('请输入最低库存量！');
      return; 
  }
 
  if(trim(document.getElementById('one_price').value)=='')
  {
      alert('请输入商品库存单价！');
      return; 
  }
   
  
 // alert(document.getElementById("state_name").value);                                            
  
  document.addForm.submit();    

}

 

function audit(val){
	if(val == 1){
		document.getElementById('state_code').value = 'c';
	}
	if(val == 2){
		document.getElementById('state_code').value = 'b';
		alert(document.getElementById('state_code').value);
	}
	document.addForm.submit();
}




